package LeetCode;

import java.util.*;

public class No46 {
    public static void main(String[] args) {
        int[] nums = {1,2,3};
        permute(nums);
    }
    public static List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> list = new ArrayList<>();
        List<Integer> list1 = new ArrayList<>();
        for(int num:nums){
            list1.add(num);
        }
        deepSeek(list1,list,0);
        return list;
    }

    public static void deepSeek(List<Integer> list1,List<List<Integer>> list,int first) {
        if(first==list1.size()){
            list.add(new ArrayList<Integer>(list1));
        }
        for (int i = first; i < list1.size(); i++) {
            Collections.swap(list1,first,i);
            deepSeek(list1,list,first+1);
            Collections.swap(list1,first,i);
        }
    }
}
